﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;
using NetDiskPRJ.Base;

namespace NetDiskPRJ.NetDisk
{
    public partial class SettingForm : NetDiskPRJ.Base.DlgForm
    {

        public static Dictionary<string, List<string>> settingdic = new Dictionary<string, List<string>>();
        public SettingForm()
        {
            InitializeComponent();

        }

        private void easSimpleButton1_Click(object sender, EventArgs e)
        {
            SaveAll();
            this.Close();
        }

        private void easSimpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void easSimpleButton3_Click(object sender, EventArgs e)
        {

        }

        private void easSimpleButton4_Click(object sender, EventArgs e)
        {

        }

        private void easSimpleButton5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void easSimpleButton6_Click(object sender, EventArgs e)
        {
            this.Close();
        }
         private void SaveAll()
        {

             if (checkBox2.Checked)
             {
                 string strName = System.Windows.Forms.Application.ExecutablePath;
                 string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1);
                 if (!System.IO.File.Exists(strName))//指定文件是否存在  
                     return;
                 Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                 if (Rkey == null)
                 {
                     Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                 }
                 Rkey.SetValue(strnewName, strName);//修改注册表，使程序开机时自动执行。 

             }
             else
             {
                 string strName = System.Windows.Forms.Application.ExecutablePath;
                 string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1);
                 Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                 Rkey.DeleteValue(strnewName, false);
             }
             if (checkBox1.Checked)
             {

                 Common.ConfigHelper.SeTconfigKeyValue("AutoLogin", "Y");
                 GlobalParams.IsAutoLogin = "Y";
             }
             else
             {
                 Common.ConfigHelper.SeTconfigKeyValue("AutoLogin", "N");
                 GlobalParams.IsAutoLogin = "N";
             }
        }

         private void SettingForm_Load(object sender, EventArgs e)
         {
              string strName = System.Windows.Forms.Application.ExecutablePath;
                 string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1);
                 if (!System.IO.File.Exists(strName))//指定文件是否存在  
                     return;
                 Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                 if (Rkey != null)
                 {
                     if (Rkey.GetValue(strnewName)!=null)
                     {
                         checkBox2.Checked = true;
                     }
                     
                 }

                 string autologin = GlobalParams.IsAutoLogin;
                 if (autologin == "Y")
                 {
                     checkBox1.Checked = true;
                 }

         }

         private void easSimpleButton3_Click_1(object sender, EventArgs e)
         {
             this.Close();
         }
    }
}